package com.xxxx.yoyo.adminweb;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xxxx.yoyo.bean.User;
import com.xxxx.yoyo.service.IUserService;
import com.xxxx.yoyo.service.impl.UserServiceImpl;
import com.xxxx.yoyo.util.PageUtil;


@WebServlet("/admin/userList")
public class UserListServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	private IUserService userService = new UserServiceImpl();
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//获取前端页面传递过来的参数page,size
		String pageStr = request.getParameter("page");
		int page = Integer.parseInt (pageStr);
		String sizeStr = request.getParameter("size");
		int size = Integer.parseInt (sizeStr);
		
		//设置导航条上的[客户管理]处于选中状态
		request.setAttribute("flag",2);
		
		//获取[用户列表]
		List<User> userList = userService.getUserList(page, size);
		//把userList存入request中，供/admin/user_list.jsp页面使用
		request.setAttribute("userList", userList);
		
		//获取用户个数
		long count = userService.getUserCount ();
		//分页信息
		String pageInfo = PageUtil.getPageTool(request, count, page, size);
		//把pageInfo存入request中，供/admin/user_list.jsp页面使用
		request.setAttribute("pageTool", pageInfo);
		
		
		//请求转发，跳转到/admin/user_list.jsp
		request.getRequestDispatcher("/admin/user_list.jsp").forward(request,response);
	}

}
